package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.FuneralBusinessEntity;

/**
 * 殡葬业务表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class FuneralBusinessProvider {

    /**
     * 增加FuneralBusiness
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertFuneralBusiness(@Param("entity") FuneralBusinessEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" funeral_business ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" dead_name ", " #{entity.deadName,jdbcType=VARCHAR} ");
                VALUES(" member_name ", " #{entity.memberName,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");

                if (entity.getAsVerified() != null) {
                    VALUES(" as_verified ", " #{entity.asVerified,jdbcType=TINYINT} ");
                }

                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改FuneralBusiness
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateFuneralBusiness(@Param("entity") FuneralBusinessEntity entity) {
        return new SQL() {
            {
                UPDATE(" funeral_business ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                SET(" member_name = #{entity.memberName,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");

                if (entity.getAsVerified() != null) {
                    SET(" as_verified = #{entity.asVerified,jdbcType=TINYINT} ");
                }

                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询FuneralBusiness列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listFuneralBusiness(@Param("entity") FuneralBusinessEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,dead_name,member_name,remark,as_verified,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" funeral_business ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getDeadName() != null) {
                    WHERE(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                }

                if (entity.getMemberName() != null) {
                    WHERE(" member_name = #{entity.memberName,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getAsVerified() != null) {
                    WHERE(" as_verified = #{entity.asVerified,jdbcType=TINYINT} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}